package niuke;

import java.math.BigInteger;
import java.util.Scanner;
public class Fibonacci数列 {
    static long min = 999999999;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        f(n);
        System.out.println(min);
    }

    public static void f(long n){
        int a1 = 0;
        int a2 = 1;
        int a3=1;
        while(a2<n){
            a1 = a2;  //1     2  3  5
            a2 = a3;  //2     3  5
            a3 = a1+a2;  //3  5  8
        }
        min = (n-a1)>(a2-n) ? (a2-n) : (n-a1);

    }
}
